package Z11_3_ReentrantLock;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.locks.ReentrantLock;

/**
 * @author： pang-yun
 * @date： 2021-11-04 13:11
 * 功能目的 ：用于  锁超时
 */

@Slf4j
public class LockOverTimeDemo {
    private static final ReentrantLock lock = new ReentrantLock();

    public static void main(String[] args) {
        Thread thread = new Thread(() -> {
            log.info("尝试获取锁");
            if (!lock.tryLock()) {
                log.info("获取锁失败");
                return;
            } else {
                log.info("success!");
                lock.unlock();
            }
        }, "t1");

        lock.lock();
        thread.start();

    }
}
